package com.yzh.wanandroid.vm

import android.app.Application
import androidx.lifecycle.LifecycleOwner
import com.yzh.core.livedata.SingleLiveEvent
import com.yzh.wanandroid.base.BaseFragmentViewModel
import com.yzh.wanandroid.model.RegistInfoData
import com.yzh.wanandroid.model.StateData
import com.yzh.wanandroid.network.retrofit.responsebean.BaseData
import com.yzh.wanandroid.network.retrofit.responsebean.LoginData

class RegisterFragmentVm(application: Application) : BaseFragmentViewModel(application) {

    val mRegister = SingleLiveEvent<StateData<RegistInfoData>>()

    var mLoginData = SingleLiveEvent<StateData<BaseData<LoginData>>>()

    fun userRegister(
        owner: LifecycleOwner,
        username: String,
        password: String,
        repassword: String
    ) {
        mUserRepository.register(owner, username, password, repassword, mRegister)
    }

    fun loginWanAndroid(owner: LifecycleOwner, username: String, password: String) {
        mUserRepository.login(owner, username, password, mLoginData)
    }

    override fun onDestory(owner: LifecycleOwner) {
        super.onDestory(owner)
        mLoginData.call()
    }
}